package main

import (
	"github.com/boltdb/bolt"
	"strconv"
	"match-spider/util/boltdb"
	"strings"
	"math"
	"fmt"
)

func main()  {
	i:=0
	t:=0
	z:=0
	boltdb.ScanTx("matchs-2017", func(tx *bolt.Tx) {

		tx.ForEach(func(name []byte, b *bolt.Bucket) error {
			b.ForEach(func(k, v []byte) error {
				content := string(v)
				s := strings.Split(content, "^")

				league := s[1]
				startAt := s[2]
				if !strings.Contains(startAt,"17-"){
					return nil
				}

				s1, _ := strconv.ParseFloat(s[4], 64)
				s2, _ := strconv.ParseFloat(s[6], 64)
				if league!="澳洲甲"{
					return nil
				}

				boltdb.Get("asia-2017", league, string(k), func(asia string) {
					asiaSlice:=strings.Split(asia,"!")
					o1:=float64(0)
					o2:=float64(0)
					p1:=float64(0)
					//p2:=float64(0)
					p3:=float64(0)
					//p4:=float64(0)
					k:=0
					for _,v:=range asiaSlice{
						asiaOdds:=strings.Split(v,"^")
						name:=asiaOdds[0]
						if name=="澳门"{
							o1,_=strconv.ParseFloat(asiaOdds[3],64)
							o2,_=strconv.ParseFloat(asiaOdds[6],64)
							p1,_=strconv.ParseFloat(asiaOdds[2],64)
							//p2,_=strconv.ParseFloat(asiaOdds[4],64)
							p3,_=strconv.ParseFloat(asiaOdds[5],64)
							//p4,_=strconv.ParseFloat(asiaOdds[7],64)
							k++
							break
						}

					}
					if k==0{
						return
					}

					if math.Abs(o1)-math.Abs(o2)==-0.25{
						//升盘
						if p1<p3{
							if s1-s2-o2>0{
								i++
							}
							if s1-s2-o2==0{
								z++
							}
							t++
						}
						if p1>p3{
							if s1-s2-o2<0{
								i++
							}
							if s1-s2-o2==0{
								z++
							}
							t++
						}



					}
					if math.Abs(o1)-math.Abs(o2)==0.25{
						//降盘
						if p1<p3{

							if s1-s2-o2<0{
								i++
							}
							t++
							if s1-s2-o2==0{
								z++
							}
						}
						if p1>p3{
							if s1-s2-o2>0{
								i++
							}
							if s1-s2-o2==0{
								z++
							}
							t++
						}



					}

				})
				return nil
			})
			return nil
		})
	})
	fmt.Println(i,z,t)
}
